#include <stdio.h>

void seed_fill(int array[][40], int x, int y, int m, int n, int tar, int fill)
{
    if (tar == array[x][y] && x >= 0 && x < m && y >= 0 && y < n) {
        array[x][y] = fill;

        seed_fill(array, x-1, y, m, n, tar, fill);
        seed_fill(array, x+1, y, m, n, tar, fill);
        seed_fill(array, x, y-1, m, n, tar, fill);
        seed_fill(array, x, y+1, m, n, tar, fill);
    }

    return;
}

int main(int argc, char *argv[])
{
	int m, n, b, book_x, book_y, lib[40][40], x, y;
	int i, j, cnt;

	scanf("%d %d", &m, &n);
	for (i=0; i<m; i++) {
		for (j=0; j<n; j++) {
			scanf("%d", &lib[i][j]);
		}
	}
    scanf("%d %d", &x, &y);

    seed_fill(lib, x-1, y-1, m, n, 0, 2);

    scanf("%d", &b);
    cnt = 0;
    for (i=0; i<b; i++) {
        scanf("%d %d", &book_x, &book_y);
        if (2 == lib[book_x-1][book_y-1]) cnt++;
    }
    printf("%d\n", b - cnt);

	return 0;
}
